#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<assert.h>
typedef int Datatype ;
typedef struct SLNode
{
	Datatype x;
	struct SLNode* next;
}SLNode;
SLNode* Initail()
{
	SLNode* phead = (SLNode*)malloc(sizeof(SLNode));
	assert(phead);
		phead->x = 0;
		phead->next = NULL;
		return phead;
}
void SLPush(SLNode* head, Datatype m)
{
	assert(head);
	SLNode* p = (SLNode*)malloc(sizeof(SLNode));
	assert(p);
	p->x = m;
	p->next = NULL;
	while (head->next)
	{
		head = head->next;
	}
	head->next = p;
}
void  SLPrint(SLNode* head)
{
	head = head->next;
	while (head)
	{
		printf("%d ", head->x);
		head = head->next;
	}
}
int main()
{
	SLNode* head = Initail();
	while (1)
	{
		int y = 0;
		scanf("%d", &y);
		if (y == 0)
			break;
		else
		{
			SLPush(head, y);
		}
	}
	SLPrint(head);
}